using System;
using System.Data;
using Jandaya.Framework.DAO;
using FirebirdSql.Data.FirebirdClient;

namespace Jandaya.Framework.Core.Pessoa
{
	public class DAOPessoaJuridica : DAO<PessoaJuridica>
	{
		public DAOPessoaJuridica(PessoaJuridica pBussinessObject, FbConnection pConnection)
		{
			BO = pBussinessObject;
			Connection = pConnection;
		}
		
		public override bool Bind(DataRow pRow){			
			BO.ID.Value = Int64.Parse(pRow["id"].ToString());
			BO.Nome  = pRow["nome"].ToString();			
			BO.CNPJ = pRow["cnpj"].ToString();
			BO.NomeFantasia = pRow["nomeFantasia"].ToString();
    		BO.RazaoSocial = pRow["razaoSocial"].ToString();
    		BO.InscricaoMunicipal = pRow["incsMunicipal"].ToString();
	   		BO.InscricaoEstadual = pRow["inscEstadial"].ToString();
			BO.Ativo = (pRow["ativo"].ToString() == "S");			
			return true;
		}
		
		public override bool Load (Int64 ID)
		{
			DataTable tb = GetDataTable(string.Format("select id, Nome, RazaoSocial, NomeFantasia, CNPJ, " +
													  "InscMunicipal, InscEstadual, Ativo  " +
														"from \"Core.Empresas\" where id = {0}", ID));
			if (tb.Rows.Count == 0)
				return false;
			else
				return Bind(tb.Rows[0]);
			
		}
	}
}

